package num52;

/**
 * @author : DuJiabao
 * @Date : 2021/1/25 14:28
 * @Project : sword-finger-offer
 * @File : null.java
 * @Desc : 两个指针，分别从两个链表出发，到末尾之后，走到另一个链表头节点，再次出发。最后一定会相遇！（有点浪漫hh）
 */
public class Solution2 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode pointA = headA;
        ListNode pointB = headB;
        while (pointA != pointB) {
            pointA = pointA != null ? pointA.next : headB;
            pointB = pointB != null ? pointB.next : headA;
        }
        return pointA;
    }
}
